package giectech.spring.data.mapper;


import giectech.spring.data.model.Coffee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

@Mapper
public interface CoffeeMapper {
    @Select("select * from t_coffee order by id")
    List<Coffee> findAllWithRowBounds(RowBounds rowBounds);

    @Select("select * from t_coffee order by id")
    List<Coffee> findAllWithParam(@Param("pageNum") int pageNum,
                                  @Param("pageSize") int pageSize);

    @Select("select * from t_coffee where id = #{id}")
    Coffee findOneCoffeeById(@Param("id") long id);

    @Select("select * from t_coffee where name=#{name}")
    List<Coffee> findOneCoffeeByName(@Param("name") String name);

    @Insert({
            "insert into T_COFFEE (NAME, PRICE, ",
            "CREATE_TIME, UPDATE_TIME)",
            "values (#{name,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT,typeHandler=giectech.spring.data.handler.MoneyTypeHandler}, ",
            "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="CALL IDENTITY()", keyProperty="id", before=false, resultType=Long.class)
    int insert(Coffee record);


    @Update({
            "update T_COFFEE",
            "set NAME = #{name,jdbcType=VARCHAR},",
            "PRICE = #{price,jdbcType=BIGINT,typeHandler=giectech.spring.data.handler.MoneyTypeHandler},",
            "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},",
            "UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}",
            "where ID = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Coffee record);

    @Delete({
            "delete from T_COFFEE",
            "where ID = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

}
